fn main() {
    println!("Hello, world!");

    //match  控制流运算符

    //允许一个值与一些列模式进行匹配,并执行匹配的模式对应的代码

    let c = Coin::Quarter(State::Alabama);

    println!("{}", value_in_cents(c));

    let five = Some(5);
    let six = plus_one(five);

    let none = plus_one(None);

    println!("six:{:?}", six);
    println!("none:{:?}", none);

    //match 匹配必须穷举所有的可能
    //可以使用_代替没有列出的值

    let v = 0u8;

    match v {
        1 => println!("1"),
        3 => println!("3"),
        _ => (),  //什么都不干
    }

    //if let 只关心一种分支

    if let 1 = v{
        println!("three");
    }

    //也可以搭配else
}

enum Coin {
    Penny,
    Nickel,
    Dime,
    Quarter(State),
}

#[derive(Debug)]
enum State {
    Alabama,
    Alaska,
}
fn value_in_cents(coin: Coin) -> u8 {
    match coin {
        Coin::Penny => 1,
        Coin::Nickel => 5,
        Coin::Dime => 10,
        Coin::Quarter(state) => {
            println!("{:?}", state);
            25
        }
    }
}
//

fn plus_one(x: Option<u32>) -> Option<u32> {
    match x {
        None => None,
        Some(i) => Some(i + 1),
    }
}
